package com.example.demo.controller;

import com.example.demo.VO.MessageVO;
import com.example.demo.VO.Result;
import com.example.demo.entity.Message;
import com.example.demo.service.MessageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (Message)表控制层
 *
 * @author hjl
 * @since 2020-11-30 19:33:02
 */
@RestController
@RequestMapping("message")
public class MessageController {
    /**
     * 服务对象
     */
    @Resource
    private MessageService messageService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Message selectOne(Integer id) {
        return this.messageService.queryById(id);
    }

    public Result Badd(Message[] messages){
        for (int i=0;i<messages.length;i++){
            messageService.insert(messages[i]);
        }
        return Result.success();
    }
    @ApiOperation(value="查看我的聊天记录",tags={"questionId"},notes="注意问题点")
    public Result selectByMy(int myId, int forId){
        Message messageme = new Message();
        messageme.setMyUserId(myId);
        Message messageyou = new Message();
        messageyou.setForUserId(forId);
        return Result.success(new MessageVO(messageService.queryByExample(messageme),messageService.queryByExample(messageyou)));
    }

}